package com.vecspace.dayu.code.ui.httphandler;

import org.springframework.beans.factory.annotation.Autowired;

import com.vecspace.dayu.code.ui.pojo.Form;
import com.vecspace.dayu.code.ui.service.FormService;
import com.vecspace.security.model.LoginContext;
import com.vecspace.web.servlet.model.BaseController;
import com.vecspace.web.servlet.model.HController;
import com.vecspace.web.servlet.model.Param;
import com.vecspace.web.servlet.model.Path;

/** DAYU-表单 httphandler
 * 在handler中进行与页面相关的处理，比如把数据转换为HTML格式等。
 * @author wanghua
*/
@HController("dayucode_formHandler")
public class FormHandler extends BaseController {

	/**根据ID查询 DAYU-表单
	 * @return Form
	 * @throws Exception
	 * @author wanghua
	 */
	@Path("getForm")
	public Form getForm(@Param("id") Long id) throws Exception {
		return formService.getForm(id);
	}
	
	/** 插入或修改 DAYU-表单 
	 * @param item	要保存的对象
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	@Path("saveForm")
	public Form saveForm(@Param("item") Form item) throws Exception {
		if (item == null){
			return null;
		}
		/*** 对item对象进行校验，如必填项，格式，逻辑关系等 ***/
		String loginUserId = LoginContext.getLoginId();
		return formService.saveViewForm(item, loginUserId);
	}

	/** 根据ID删除 DAYU-表单 
	 * @param id	主键值
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	@Path("deleteForm")
	public void deleteForm(@Param("id") Long id) throws Exception {
		formService.deleteForm(id);
	}

	/************* property ********************/
	@Autowired
	private FormService formService;

}
